/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Customer")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c ORDER BY c.cName ASC"),
    @NamedQuery(name = "Customer.findByCId", query = "SELECT c FROM Customer c WHERE c.cId = :cId"),
    @NamedQuery(name = "Customer.findByCName", query = "SELECT c FROM Customer c WHERE c.cName = :cName"),
    @NamedQuery(name = "Customer.findByCAddr", query = "SELECT c FROM Customer c WHERE c.cAddr = :cAddr"),
    @NamedQuery(name = "Customer.findByCCity", query = "SELECT c FROM Customer c WHERE c.cCity = :cCity"),
    @NamedQuery(name = "Customer.findByCState", query = "SELECT c FROM Customer c WHERE c.cState = :cState"),
    @NamedQuery(name = "Customer.findByCZip", query = "SELECT c FROM Customer c WHERE c.cZip = :cZip"),
    @NamedQuery(name = "Customer.findByCContact", query = "SELECT c FROM Customer c WHERE c.cContact = :cContact"),
    @NamedQuery(name = "Customer.findByCPhone", query = "SELECT c FROM Customer c WHERE c.cPhone = :cPhone"),
    @NamedQuery(name = "Customer.findByCNotes", query = "SELECT c FROM Customer c WHERE c.cNotes = :cNotes"),
    @NamedQuery(name = "Customer.findByCEmail", query = "SELECT c FROM Customer c WHERE c.cEmail = :cEmail"),
    @NamedQuery(name = "Customer.findByCTerms", query = "SELECT c FROM Customer c WHERE c.cTerms = :cTerms"),
    @NamedQuery(name = "Customer.findByCdist", query = "SELECT c FROM Customer c WHERE c.cdist = :cdist"),
    @NamedQuery(name = "Customer.findByCActive", query = "SELECT c FROM Customer c WHERE c.cActive = :cActive"),
    @NamedQuery(name = "Customer.findByCustHold", query = "SELECT c FROM Customer c WHERE c.custHold = :custHold"),
    @NamedQuery(name = "Customer.findByCustGroup", query = "SELECT c FROM Customer c WHERE c.custGroupID.customerGroupID = ?1 ORDER BY c.cName ASC")})
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CId")
    private Long cId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 40)
    @Column(name = "CName")
    private String cName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 40)
    @Column(name = "CAddr")
    private String cAddr;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 30)
    @Column(name = "CCity")
    private String cCity;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 20)
    @Column(name = "CState")
    private String cState;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CZip")
    private int cZip;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 40)
    @Column(name = "CContact")
    private String cContact;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 20)
    @Column(name = "CPhone")
    private String cPhone;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 200)
    @Column(name = "CNotes")
    private String cNotes;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 100)
    @Column(name = "CEmail")
    private String cEmail;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CTerms")
    private int cTerms;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Cdist")
    private boolean cdist;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CActive")
    private boolean cActive;
    @Basic(optional = false)
    @NotNull
    @Column(name = "custHold")
    private int custHold;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 400)
    @Column(name = "CEmailCC")
    private String cEmailCC;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cust")
    private Collection<PendingSO> pendingSOCollection;
    @JoinColumn(name = "CustGroupID", referencedColumnName = "CustomerGroupID", nullable=true)
    @ManyToOne(optional = true)
    private CustomerGroup custGroupID;
    @JoinColumn(name = "discountCode", referencedColumnName = "DiscID", nullable=true)
    @ManyToOne(optional = true)
    private DiscountCode discountCode;
    @JoinColumn(name = "custRouteID", referencedColumnName = "RouteID", nullable=true)
    @ManyToOne(optional = true)
    private Routes custRouteID;
    @OneToMany(mappedBy = "custID")
    private Collection<Sales> salesCollection;
    @OneToMany(mappedBy = "sOCust", cascade = CascadeType.ALL)
    private Collection<SalesOrder> soCollection;
    @OneToMany(mappedBy = "kegCust")
    private Collection<ScanTblKeg> kegCollection;
    @OneToMany(mappedBy = "trCust")
    private Collection<Administration> adminCollection1;
    @OneToMany(mappedBy = "actCustomer")
    private Collection<ACT> actCollection;
    @OneToMany(mappedBy = "invSaleCustID")
    private Collection<InvSalesLines> invSalesLinesCollection;
    @OneToMany(mappedBy = "atCustomer")
    private Collection<ATCust> atCollection;

    public Customer() {
    }

    public Customer(Long cId) {
        this.cId = cId;
    }

    public Customer(Long cId, String cName, String cAddr, String cCity, String cState, int cZip, String cContact, String cPhone, String cNotes, String cEmail, int cTerms, boolean cdist, boolean cActive, int custHold, String cEmailCC) {
        this.cId = cId;
        this.cName = cName;
        this.cAddr = cAddr;
        this.cCity = cCity;
        this.cState = cState;
        this.cZip = cZip;
        this.cContact = cContact;
        this.cPhone = cPhone;
        this.cNotes = cNotes;
        this.cEmail = cEmail;
        this.cTerms = cTerms;
        this.cdist = cdist;
        this.cActive = cActive;
        this.custHold = custHold;
        this.cEmailCC = cEmailCC;
    }

    public Long getCId() {
        return cId;
    }

    public void setCId(Long cId) {
        this.cId = cId;
    }

    public String getCName() {
        return cName;
    }

    public void setCName(String cName) {
        this.cName = cName;
    }

    public String getCAddr() {
        return cAddr;
    }

    public void setCAddr(String cAddr) {
        this.cAddr = cAddr;
    }

    public String getCCity() {
        return cCity;
    }

    public void setCCity(String cCity) {
        this.cCity = cCity;
    }

    public String getCState() {
        return cState;
    }

    public void setCState(String cState) {
        this.cState = cState;
    }

    public int getCZip() {
        return cZip;
    }

    public void setCZip(int cZip) {
        this.cZip = cZip;
    }

    public String getCContact() {
        return cContact;
    }

    public void setCContact(String cContact) {
        this.cContact = cContact;
    }

    public String getCPhone() {
        return cPhone;
    }

    public void setCPhone(String cPhone) {
        this.cPhone = cPhone;
    }

    public String getCNotes() {
        return cNotes;
    }

    public void setCNotes(String cNotes) {
        this.cNotes = cNotes;
    }

    public String getCEmail() {
        return cEmail;
    }

    public void setCEmail(String cEmail) {
        this.cEmail = cEmail;
    }

    public int getCTerms() {
        return cTerms;
    }

    public void setCTerms(int cTerms) {
        this.cTerms = cTerms;
    }

    public boolean getCdist() {
        return cdist;
    }

    public void setCdist(boolean cdist) {
        this.cdist = cdist;
    }

    public boolean getCActive() {
        return cActive;
    }

    public void setCActive(boolean cActive) {
        this.cActive = cActive;
    }

    public CustomerGroup getCustGroupID() {
        return custGroupID;
    }

    public void setCustGroupID(CustomerGroup custGroupID) {
        if(custGroupID != null && custGroupID.getCustomerGroupID() != null){
            this.custGroupID = custGroupID;
        }
    }

    public DiscountCode getDiscountCode() {
        return discountCode;
    }

    public void setDiscountCode(DiscountCode discountCode) {
        if(discountCode != null && discountCode.getDiscID() != null){
            this.discountCode = discountCode;
        }
    }

    public int getCustHold() {
        return custHold;
    }

    public void setCustHold(int custHold) {
        this.custHold = custHold;
    }

    public Routes getCustRouteID() {
        return custRouteID;
    }

    public void setCustRouteID(Routes custRouteID) {
        if(custRouteID != null && custRouteID.getRouteID() != null){
            this.custRouteID = custRouteID;
        }
    }

    public String getCEmailCC() {
        return cEmailCC;
    }

    public void setCEmailCC(String cEmailCC) {
        this.cEmailCC = cEmailCC;
    }

    @XmlTransient
    public Collection<SalesOrder> getSOCollection() {
        return soCollection;
    }

    public void setSOCollection(Collection<SalesOrder> soCollection) {
        this.soCollection = soCollection;
    }

    @XmlTransient
    public Collection<PendingSO> getPendingSOCollection() {
        return pendingSOCollection;
    }

    public void setPendingSOCollection(Collection<PendingSO> pendingSOCollection) {
        this.pendingSOCollection = pendingSOCollection;
    }

    @XmlTransient
    public Collection<Sales> getSalesCollection() {
        return salesCollection;
    }

    public void setSalesCollection(Collection<Sales> salesCollection) {
        this.salesCollection = salesCollection;
    }

    @XmlTransient
    public Collection<ScanTblKeg> getKegCollection() {
        return kegCollection;
    }

    public void setKegCollection(Collection<ScanTblKeg> kegCollection) {
        this.kegCollection = kegCollection;
    }

    @XmlTransient
    public Collection<Administration> getAdminCollection1() {
        return adminCollection1;
    }

    public void setAdminCollection1(Collection<Administration> adminCollection1) {
        this.adminCollection1 = adminCollection1;
    }

    @XmlTransient
    public Collection<ACT> getACTCollection() {
        return actCollection;
    }

    public void setACTCollection(Collection<ACT> acbCollection) {
        this.actCollection = acbCollection;
    }

    @XmlTransient
    public Collection<ATCust> getAtCollection() {
        return atCollection;
    }

    public void setAtCollection(Collection<ATCust> atCollection) {
        this.atCollection = atCollection;
    }

    @XmlTransient
    public Collection<InvSalesLines> getInvSalesLinesCollection() {
        return invSalesLinesCollection;
    }

    public void setInvSalesLinesCollection(Collection<InvSalesLines> invSalesLinesCollection) {
        this.invSalesLinesCollection = invSalesLinesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cId != null ? cId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.cId == null && other.cId != null) || (this.cId != null && !this.cId.equals(other.cId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Customer[ cId=" + cId + " ]";
    }
    
}
